package com.yukefms.rule.formula.basis;

import com.yukefms.engine.running.MatchedStatus;
import com.yukefms.engine.running.RunningContext;
import com.yukefms.jointpoint.BodyPointCloud;
import com.yukefms.jointpoint.GeometryAdaptorForPointCalculator;
import com.yukefms.jointpoint.TolerantEpsilon;
import com.yukefms.rule.formula.interfaces.AbstractStaticBAFormula;
import com.yukefms.rule.formula.interfaces.StaticBAFormula;

/***
 * @desc  {@code AtSameFrontLineFormula} is to describe related two body joint points at same distance in front of Camera
 * , Normally, two body points are two feet and used to define the performer's
 *  two foots standing together.
 */
public class AtSameFrontLineFormula extends AbstractStaticBAFormula implements StaticBAFormula {

    private String jointType1 ;
    private String jointType2 ;


    public AtSameFrontLineFormula(String jointType1, String jointType2) {
        super(jointType1, jointType2) ;
        this.jointType1 = jointType1 ;
        this.jointType2 = jointType2 ;

    }

    @Override
    public MatchedStatus matched(BodyPointCloud bodyPointCloud, RunningContext context) {
        // for test
 /*       System.out.println("Angle:" + GeometryAdaptorForPointCalculator.angle(bodyPointCloud.getPosition(jointType1),
                bodyPointCloud.getPosition(jointType2),
                bodyPointCloud.getPosition(jointType3))) ;
        System.out.println("Epsilon: " + TolerantEpsilon.ANGLE_EPSILON) ;*/
        // check if the formula is matched,
        // if it matched, then
        double distance = Math.abs(bodyPointCloud.getPosition(jointType1).getZ() - bodyPointCloud.getPosition(jointType2).getZ()) ;
        //System.out.println("dis: " + distance) ;
        if (distance <= TolerantEpsilon.LENGTH_EPSILON)
        {
            // if has successor , then pass to the next formula.
            if (this.successor != null) {
                return this.successor.matched(bodyPointCloud, context);
            } else {
                return MatchedStatus.TRUE;
            }
        }
        // if does not matched
        return MatchedStatus.FALSE;
    }



}
